package com.yzc.android.common.app;

import android.content.Context;

import com.yzc.android.KDApp;
import com.yzc.android.utils.PreferencesUtils;

/**
 * Created by yzc on 15/9/18.
 */
public class AppConfigManager implements IAppConfig {
    public static final boolean isDebug = false;

    public static ContextMode currentContextMode = ContextMode.ONLINE;

    private static Context mContext = KDApp.getInstance().getApplicationContext();

    private String mApiHostUrl;

    public enum ContextMode {
        TEST(0), PRE_ONLINE(1), ONLINE(2), DEVELOP(3);

        private int value = 0;

        ContextMode(int value) {    //    必须是private的，否则编译错误
            this.value = value;
        }

        public static ContextMode valueOf(int value) {    //    手写的从int到enum的转换函数
            switch (value) {
                case 0:
                    return TEST;
                case 1:
                    return PRE_ONLINE;
                case 2:
                    return ONLINE;
                case 3:
                    return DEVELOP;
                default:
                    return ONLINE;
            }
        }

        public int value() {
            return this.value;
        }
    }

    public static void loadContextMode() {
        int status = PreferencesUtils.getInt(mContext, "ContextMode", currentContextMode.value());
        switch (status) {
            case 0:
                currentContextMode = ContextMode.TEST;
                break;
            case 1:
                currentContextMode = ContextMode.PRE_ONLINE;
                break;
            case 2:
                currentContextMode = ContextMode.ONLINE;
                break;
            case 3:
                currentContextMode = ContextMode.DEVELOP;
                break;
        }
    }

    public static void saveContextMode(int i) {
        PreferencesUtils.putInt(mContext, "ContextMode", i);
        loadContextMode();
    }

    @Override
    public String getApiHostUrl() {
        switch (currentContextMode) {
            case ONLINE:
                mApiHostUrl = "http://www.baidu.com/";
                break;
            case PRE_ONLINE:
                mApiHostUrl = "http://www.baidu.com/";
                break;
            case TEST:
                mApiHostUrl = "http://www.baidu.com/";
                break;
            case DEVELOP:
                mApiHostUrl = "http://www.baidu.com/";
                break;
        }
        return mApiHostUrl;
    }

    @Override
    public String getAppVersion() {
        return null;
    }

    @Override
    public String getAppKey() {
        return null;
    }

    @Override
    public String getSecureKey() {
        return null;
    }

    @Override
    public int getHttpTimeout() {
        return 0;
    }
}
